from common.case import read_cases, send_request, check
from common.db import DB
import pytest
DB().init_db('signup.sql')
cases=read_cases('signup.xlsx',['用例编号', '用例说明', '接口路径','请求方法','请求类型', '参数', '预期结果','验库sql','预期行数'])
# @pytest.fixture(scope = 'module', autouse=True)
@pytest.mark.parametrize('case_info,url,method,request_type,args,expect,check_sql,expect_rows', cases)
def test_signup(case_info,url,method,request_type,args,expect,check_sql,expect_rows):

    res_type,actual=send_request(url,method,request_type,args)

    passed,msg=check(case_info,res_type,actual,expect)  #检查响应结果是否正确
    try:
        assert passed,msg
    finally:
        passed,msg=DB().checkdb(case_info,args,check_sql,expect_rows)

        assert passed,msg
if __name__=='__main__':
    pytest.main(['--tb=no', '--html=../report/signup.html',
                 '--log-format=%(asctime)s [%(levelname)s] %(message)s [%(filename)s:%(lineno)s]'
                    , '--log-date-format=%Y-%m-%d %H:%M:%S', 'login.py'])